import { PureComponent } from 'react';
import {
  Row,
  Col,
  Form,
  Input,
	Modal,
} from 'antd';

const FormItem = Form.Item;


// 修改表单
@Form.create()
class UpdateForm extends PureComponent {
    static defaultProps = {
        handleUpdate: () => {},
    handleUpdateModalVisible: () => {},
values: {},
};

constructor(props) {
    super(props);

    this.state = {
        formVals: {
        	parentid: props.values.parentid,
            levelcode: props.values.levelcode,
            name: props.values.name,
            enname: props.values.enname,
            handler: props.values.handler,
            icon: props.values.icon,
            id: props.values.id,
                
        },
    };


}

 handleLocalUpdate = () => {
    const { form, handleUpdate } = this.props;
    const { formVals: oldValue } = this.state;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      const formVals = { ...oldValue, ...fieldsValue };
      this.setState(
        {
          formVals,
        }
      );
     
     handleUpdate(formVals);

    });
  };


renderContent = (formVals) => {
    const { form } = this.props;

    return (
        <Form  layout="vertical">


            <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

	                <Col  md={12} sm={24}>
		                <FormItem  label="操作名称">
		                    {form.getFieldDecorator('name', {
		                    rules: [{ required: true, message: '请输入操作名称！', min: 1 }],
		                    initialValue: formVals.name,
		                    })(<Input placeholder="请输入" />)}
		                </FormItem>
	                </Col>
	
	
	                <Col  md={12} sm={24}>
		                <FormItem  label="英文名称">
		                    {form.getFieldDecorator('enname', {
		                    rules: [{ required: true, message: '请输入英文名称！', min: 1 }],
		                    initialValue: formVals.enname,
		                    })(<Input placeholder="请输入" />)}
		                </FormItem>
	                </Col>

            </Row>

            <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

                    <Col  md={12} sm={24}>
	                    <FormItem  label="操作方法">
	                        {form.getFieldDecorator('handler', {
	                        rules: [{ required: false, message: '请输入操作方法！', min: 1 }],
	                        initialValue: formVals.handler,
	                        })(<Input placeholder="请输入" />)}
	                    </FormItem>
                    </Col>

                    <Col  md={12} sm={24}>
	                    <FormItem  label="图标">
	                        {form.getFieldDecorator('icon', {
	                        rules: [{ required: false, message: '请输入图标！', min: 1 }],
	                        initialValue: formVals.icon,
	                        })(<Input placeholder="请输入" />)}
	                    </FormItem>
                    </Col>

			</Row>
                  
    </Form>
);

};



render() {
    const { updateModalVisible, handleUpdateModalVisible, values} = this.props;
    const {  formVals } = this.state;

    return (
        <Modal
    width={800}
    height={800}
    bodyStyle={{ padding: '32px 40px 48px' }}
    destroyOnClose
    title="修改"
    visible={updateModalVisible}
    onOk={() => this.handleLocalUpdate()}
    onCancel={() => handleUpdateModalVisible(false, values)}
    afterClose={() => handleUpdateModalVisible()}
>

    {this.renderContent(formVals)}
</Modal>
);
}
}

export default UpdateForm;